package com.sky.chapter1.join;

/**
 * Author by cqb, Date on 2020/6/27，23:30
 */
public class joinDemo2 {

    public static void main(String[] args) throws InterruptedException {
        //创建线程one
        Thread threadOne = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("threadOne begin run!");
                for (; ; ) {
                }
            }
        });
        //获取主线程
        final Thread mainThread = Thread.currentThread();
        //创建线程Two
        Thread threadTwo = new Thread(new Runnable() {
            //            int atomicInteger=0;
            @Override
            public void run() {
                try {
                    Thread.sleep(1000);
//                    for (int i=0;i<100;i++){
//                        System.out.println("threadTwo is running "+i);
//                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                //中断主线程
                mainThread.interrupt();
//                System.out.println(atomicInteger);
            }

        });
        //启动子线程
        threadOne.start();
        //延迟一秒启动线程
        threadTwo.start();
        try {//等待线程one执行结束
            threadOne.join();
        } catch (InterruptedException e) {
            System.out.println("main thread:" + e);
        }
    }
}
